home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / AMarquee / examples / killclients.rexx < prev    next >
OS/2 REXX Batch file  |  1998-06-24  |  2KB  |  87 lines

  1. /*************************************************
  2.  
  3.    killclients.rexx
  4.  
  5.    Author: Jeremy Friesner (jaf@chem.ucsd.edu)
  6.    
  7.    An ARexx script that will kick off localhost's
  8.    AMarqueed server any AMarquee clients that match 
  9.    the given description.
  10.  
  11.    Usage:  rx killclients.rexx hostnames [lognames]
  12.    
  13.    (hostnames) should be a regular expression denoting
  14.    the hostnames of the client or clients to be kicked
  15.    off.  (e.g. sdcc8.ucsd.edu or #?.edu)
  16.    
  17.    (lognames) should be a regular expression denoting
  18.    the lognames of the AMarquee client or clients to
  19.    be kicked off (e.g. #?Netris or QAmiTrack).  If
  20.    not specified, it will default to #?.
  21.    
  22.    Example: rx killclients.rexx #? #?
  23.    
  24.    Note that you must have given localhost 
  25.    AMARQUEED_KILLCLIENTS privilege in order for
  26.    this script to work.
  27.  
  28. ***************************************************/
  29.  
  30. parse arg hostnames lognames .
  31.  
  32. if ((serverName == '?')|(length(hostnames) = 0)) then do
  33.   say "Usage: rx killclients.rexx <hostnames> [logNames]"
  34.   exit
  35.   end
  36.   
  37. serverName   = 'localhost'  /* hardcoded for now */
  38. portNum = 2957
  39. logName = 'killclients.rexx'
  40.  
  41. if (length(lognames) = 0) then lognames = '#?'
  42.  
  43. /* We need to trap all the different ways the script could exit,
  44.    so that we can be sure any allocated QSessions or QMessages are
  45.    freed properly */
  46. signal on error
  47. signal on syntax
  48. signal on halt
  49. signal on break_c
  50.  
  51. /* Used to track allocated QSession */
  52. session = 0
  53.  
  54. /* Note the offset MUST be -204, and not -30 like in many other
  55.    libraries!  Note also that we require amarquee.library v46 or higher */
  56. check = addlib('amarquee.library', 0, -204, 46)
  57.  
  58. say "Connecting to server " || serverName || " on port " || portNum || " as " || logName
  59. session = QNewSession(serverName, portNum, logName)
  60. if (session > 0) then 
  61. do
  62.   victims = "/" || hostnames || "/" || lognames
  63.   say "Killing: " || victims
  64.   
  65.   call QRequestPrivilegesOp(session, QPRIV_KILLCLIENTS)
  66.  
  67.   /* Note that this won't work if the server doesn't give us
  68.      this privilege; this script doesn't check to see if the
  69.      privilege was actually granted, but rather assumes that it
  70.      was. */
  71.   call QKillClientsOp(session,victims)              
  72.   
  73.   /* And off it goes... */
  74.   call QGo(session)
  75. end
  76.  
  77. /* Our error handling/cleanup routine starts here */
  78. ERROR:
  79. SYNTAX:
  80. HALT:
  81. BREAK_C:
  82.   say "Cleaning up..."
  83.   if (session > 0) then do
  84.     call QFreeSession(session)
  85.     end
  86.   exit
  87.